//
//  HHSelectedTextField.m
//  Flower
//
//  Created by 花花 on 2016/12/13.
//  Copyright © 2016年 花花. All rights reserved.
//

#import "HHSelectedTextField.h"
typedef UIView *(^SetupPickerViewBlock)();
@interface HHSelectedTextField()


@property(nonatomic, copy) SetupPickerViewBlock setupPickerViewBlock;

@property(nonatomic, strong) NSDateFormatter *formatter;

@property(nonatomic, copy) void(^setupToolBarBlock)(HHToolBar *toolBar);


@end
@implementation HHSelectedTextField

- (void)setuptoolBarWithHandler:(void(^)(HHToolBar *toolBar))handler{

    self.setupToolBarBlock = [handler copy];


}
-(void)showSingleColPickerWithToolBarText:(NSString *)toolBarText withData:(NSArray<NSString *>*)data withDefault:(NSInteger)defaultIndex
                        withCancelHandler:(CancelHandler)cancelHandler withDoneHandler:(SingDoneCallback)doneHandler{


    __weak typeof(self)weakSelf = self;
    
    self.setupPickerViewBlock = ^UIView *{
    
       HHSinglePickerView *single =[[HHSinglePickerView alloc]initWithToolBarText:toolBarText withDefaultIndex:defaultIndex withData:data withValueDidChangeHandler:^(NSString *selectedValue) {
            
            __strong typeof(self)strongSelf = weakSelf;
            
            if (strongSelf) {
                strongSelf.text  = selectedValue;
            }
        } cancelOnClick:^(UIButton *btn) {
            
            __strong typeof(self)strongSelf = weakSelf;
            
            if (strongSelf) {
                [strongSelf endEditing:YES];
                
                if (cancelHandler) {
                    cancelHandler();
                }
            }
            
        } doneOnClick:^(NSInteger selectedIndex, NSString *selectedValue) {
            __strong typeof(self)strongSelf = weakSelf;
            if (strongSelf) {
                [strongSelf endEditing:YES];
            
                if (doneHandler) {
                    doneHandler(strongSelf,selectedIndex,selectedValue);
                }
            
            }
            
        }];
        
        return single;
    };

}

@end
